import cv2

def save():
    cap = cv2.VideoCapture(0)

    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 640)
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, 480)

    fourcc_i420 = cv2.VideoWriter_fourcc(*'I420')
    fourcc_xvid = cv2.VideoWriter_fourcc(*'XVID')
    fourcc_mp4v = cv2.VideoWriter_fourcc(*'mp4v')

    out_i420 = cv2.VideoWriter('8/output_i420.avi', fourcc_i420, 20.0, (640, 480))
    out_xvid = cv2.VideoWriter('8/output_xvid.avi', fourcc_xvid, 20.0, (640, 480))
    out_mp4v = cv2.VideoWriter('8/output_mp4v.mp4', fourcc_mp4v, 20.0, (640, 480))

    while True:
        ret, frame = cap.read()
        
        out_i420.write(frame)
        out_mp4v.write(frame)
        out_xvid.write(frame)

        cv2.imshow('frame', frame)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    out_i420.release()
    out_xvid.release()
    out_mp4v.release()
    cv2.destroyAllWindows()

def main():
    save()

if __name__ == '__main__':
    main()